Text File | 1993-06-21 | 921 b | 35 lines | [TEXT/MPAD]
--This example simulates a projectile with air friction proportional to its velocity. Upper case variables are {x,y} vectors. See example "falling" for an example in 1 dimension.
-- initial conditions
init = V:={2,50}, -- velocity (mostly upward)
P:={0,0}, -- position
t:=0
stepto(stop) = init when stop=0,
(V:=V+A*dt,
P:=P+V*dt,
t:=t+dt) while t<stop
A=F/m
Fgravity = {0,-m*g}
Fdrag = -k*V
F=Fgravity+Fdrag
g=9.8 -- accelleration due to gravity
k=0 -- friction coefficient
m=300 -- mass of object
dt=.1 -- time step for simulation
Position(t1) = stepto(t1),P
-- parametric plot of position for t=0 to 10 -- {x,y} plot runs X from 0 to 1. Create new variable "tn" that runs 0 to tmax.